# coding=utf-8
from functools import wraps

from plant.base.beanret import BeanRet
from plant.base.cachedata import CacheData
from plant.base.tools.cachedataclient import CacheDataClient


def sso(func):
    """
    登录拦截器
    :param func:
    :return:
    """

    @wraps(func)
    def decorated_function(*args, **kwargs):
        jobnumber = CacheData().toObj(CacheDataClient().read()).getJobnumber
        if jobnumber:
            # if 'jobnumber' in session:
            return func(*args, **kwargs)
        else:
            return BeanRet().toJson()

    return decorated_function
